<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<!-- 6. 动态添加删除数据 -->

<body>
  <div id="app">
    <input type="text" v-model="newValue" placeholder="输入姓名">
    <button @click="addItem">增加</button>
    <ul>
      <li v-for="(item, index) in items">
        {{ item }}
        <button @click="removeItem(index)">删除</button>
      </li>
    </ul>
  </div>
</body>
<script src="./vue.js"></script>
<script>
  const { createApp, ref } = Vue;
  createApp({
    setup() {

      const items = ref(['李敏', '李辉', '二蛋']);
      const newValue = ref('');
      function addItem() {
        
          items.value.push(newValue.value);
          newValue.value = '';
        
      }
      function removeItem(index) {
        items.value.splice(index, 1);   
      }

      return {
        items,
        newValue,
        addItem,
        removeItem
      }
    }
  }).mount('#app')
</script>

</html>